package com.compass.ui.client;

import com.extjs.gxt.ui.client.Style.ButtonScale;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class CompassDock extends LayoutContainer
{
	ContentPanel north;
	ContentPanel center;
	ContentPanel south;
	PilotPanel pilotPanel;
	Image img;
	
	public 	CompassDock()
	{
		north = new ContentPanel();
		center = new ContentPanel();
		south = new ContentPanel();
		pilotPanel = new PilotPanel();
	}
	
	protected void onRender(Element target, int index)
	{
		super.onRender(target, index);
		final BorderLayout layout = new BorderLayout();
		setLayout(layout);
		setStyleAttribute("padding", "5px");
		
		BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH, (float) .055);
		northData.setSplit(false);
		northData.setMargins(new Margins(0, 0, 5, 0));
		
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setSplit(false);
		BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH, (float) .055);
		southData.setSplit(false);
		southData.setMargins(new Margins(5, 0, 0, 0));
		
		north.setHeaderVisible(false);
		north.setBodyStyle("background-image:url(resources/images/header.jpg)");
		
		center.setHeaderVisible(false);
		center.setBodyStyle("padding: 5px");
		center.setScrollMode(Scroll.AUTO);
		
		south.setHeaderVisible(false);
		south.setWidth("100%");
		south.setHeight("100%");
		center.add(pilotPanel);
		FlexTable toolTable = new FlexTable();
		
		Button plmButton = new Button("PLM");
		Button erpButton = new Button("ERP");
		Button scmButton = new Button("SCM");
		Button tool1Button = new Button("Outil 1");
		Button tool2Button = new Button("Outil 2");
		Button tool3Button = new Button("Outil 3");
		
		plmButton.setScale(ButtonScale.LARGE);
		erpButton.setScale(ButtonScale.LARGE);
		scmButton.setScale(ButtonScale.LARGE);
		tool1Button.setScale(ButtonScale.LARGE);
		tool2Button.setScale(ButtonScale.LARGE);
		tool3Button.setScale(ButtonScale.LARGE);
		
		toolTable.setWidget(0, 0, plmButton);
		toolTable.setWidget(0, 1, erpButton);
		toolTable.setWidget(0, 2, scmButton);
		toolTable.setWidget(0, 3, tool1Button);
		toolTable.setWidget(0, 4, tool2Button);
		toolTable.setWidget(0, 5, tool3Button);
		toolTable.setWidth("50%");

		FlexTable sysTable = new FlexTable();
		Button screenButton = new Button("Capture ecran");
		Button reportButton = new Button("Création rapport");
		
		screenButton.setScale(ButtonScale.LARGE);
		reportButton.setScale(ButtonScale.LARGE);
		reportButton.addListener(Events.OnClick, new Listener<ButtonEvent>()
		{
			@Override
			public void handleEvent(ButtonEvent be)
			{
				Window.open(GWT.getHostPageBaseURL() + "CompassReport.html", "Report", "fullscreen=yes");
			}
		});
		
		sysTable.setWidget(0, 0, screenButton);
		sysTable.setWidget(0, 1, reportButton);
		sysTable.setWidth("50%");
		
		FlexTable bottomTable = new FlexTable();
		bottomTable.setWidget(0, 0, toolTable);
		bottomTable.setWidget(0, 1, sysTable);
		bottomTable.setWidth("100%");
		bottomTable.setBorderWidth(1);
		
		south.add(bottomTable);
		add(north, northData);
		add(center, centerData);
		add(south, southData);
	}
	
	public ContentPanel	getPanel(LayoutRegion region)
	{
		if (region.compareTo(LayoutRegion.NORTH) == 0)
			return north;
		else if (region.compareTo(LayoutRegion.CENTER) == 0)
			return center;
		else if (region.compareTo(LayoutRegion.SOUTH) == 0)
			return south;
		return null;
	}
	
}
